Skip to content

feature: Implement Game Sessions backend module - #630

Merged
phertyameen merged 1 commit into
MindBlockLabs:mainfrom
limxiy:feature/game-sessions-module-611
Aug 19, 2026
Merged

feature: Implement Game Sessions backend module#630
phertyameen merged 1 commit into
MindBlockLabs:mainfrom
limxiy:feature/game-sessions-module-611

Conversation

@limxiy

@limxiy limxiy commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements the game-sessions NestJS module as specified in #611.

closes #611


What's included

Entity

  • GameSession TypeORM entity with all fields from the spec: userId, guestId, status, difficulty, selectedCategories, challengeCount, currentChallenge, score, xpEarned, startedAt, completedAt.

State machine

  • GameSessionStatus enum: CREATED, ACTIVE, PAUSED, COMPLETED, EXPIRED, ABANDONED.
  • SESSION_TRANSITIONS map enforces valid transitions; terminal-state guard prevents mutations after COMPLETED / EXPIRED / ABANDONED.

Service (GameSessionsService)

  • create() – session creation for authenticated users and guests.
  • findAllByUser() – list all sessions for a user.
  • findActiveSession() – retrieve the single active session.
  • findById() – 404-safe retrieval.
  • findAndVerifyOwnership() – ownership enforcement (403 for non-owners).
  • updateStatus() – validated state transitions with side-effects (stamp startedAt, completedAt, persist score/xpEarned).
  • completeSession() – convenience wrapper for marking COMPLETED.
  • expireIdleSessions() – bulk-expire stale sessions (for scheduled jobs).

Controller (GameSessionsController)

Method Endpoint Description
POST /game-sessions Create session
GET /game-sessions List all sessions (auth user)
GET /game-sessions/active Get current active session
GET /game-sessions/:id Get session by ID (ownership checked)
PATCH /game-sessions/:id/status Transition session status

DTOs

  • CreateGameSessionDto – with class-validator and Swagger decorators.
  • UpdateGameSessionStatusDto – with optional score/xpEarned for completion.
  • GameSessionResponseDto – full Swagger-documented response shape.

Module

  • GameSessionsModule registered in AppModule.

Testing

26 unit tests covering:

  • All valid and invalid state transitions
  • Session creation (authenticated + guest)
  • CRUD operations
  • Ownership enforcement (user + guest)
  • expireIdleSessions bulk expiry
Tests: 163 passed, 163 total (19 suites)

- GameSession entity with all required fields (userId, guestId, status,
  difficulty, selectedCategories, challengeCount, currentChallenge,
  score, xpEarned, startedAt, completedAt)
- GameSessionStatus enum: CREATED, ACTIVE, PAUSED, COMPLETED, EXPIRED, ABANDONED
- Full state machine with SESSION_TRANSITIONS map and terminal-state guard
- GameSessionsService: create, findAllByUser, findActiveSession, findById,
  findAndVerifyOwnership, updateStatus, completeSession, expireIdleSessions
- GameSessionsController: POST /, GET /, GET /active, GET /:id, PATCH /:id/status
- DTOs with class-validator + Swagger decorators
- 26 unit tests covering state machine, CRUD, ownership, and expiry logic

closes MindBlockLabs#611
@vercel

vercel Bot commented Aug 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
mind-block-app-frontend Skipped Skipped Aug 19, 2026 1:42pm

@limxiy limxiy changed the title feat(game-sessions): implement Game Sessions backend module feature: Implement Game Sessions backend module Aug 19, 2026
@limxiy

limxiy commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Can you please approve vercel deployment?

@phertyameen phertyameen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue well accomplished

@phertyameen
phertyameen merged commit 22f3503 into MindBlockLabs:main Aug 19, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create the Game Session Backend Module

2 participants